public class Song {
	
	private int RowId;
	private int Quantity;
	private String Artist;
	private String Title;
	private int Duration;
	private int Size;
	private String Url;
	
	////////////// Constructor 
	public Song() {
		RowId = 0;
		Quantity = 1;
		Artist = "-";
		Title = "-";
		Duration = 0;
		Size = 0;
		Url = "-";
	}
	
	public Song(int quantity, String artist, String title, int duration, int size) {
		this.Quantity = quantity;
		this.Artist = artist;
		this.Title = title;
		this.Duration = duration;
		this.Size = size;
	}

	// Public functions
	public void fetchDetails() {
		
		// TODO: Fetch details of song
			


	}

	////////////// Properties 
	public int getRowId() {
		return RowId;
	}

	public void setRowId(int rowId) {
		RowId = rowId;
	}

	public int getQuantity() {
		return Quantity;
	}

	public void setQuantity(int quantity) {
		Quantity = quantity;
	}

	public String getArtist() {
		return Artist;
	}

	public void setArtist(String artist) {
		Artist = artist;
	}

	public String getTitle() {
		return Title;
	}

	public void setTitle(String title) {
		Title = title;
	}

	public int getDuration() {
		return Duration;
	}
	
	public void setDuration(int duration) {
		Duration = duration;
	}

	public int getSize() {
		return Size;
	}
	
	public void setSize(int size) {
		Size = size;
	}

	public String getUrl() {
		return Url;
	}

	public void setUrl(String url) {
		Url = url;
	}

	////////////// Special properties 

	public int getFormattedSize() {
		return bytesToMB(Size);
	}

	public String getFormattedDuration() {
		return secondsToMMSS(Duration);
	}

	public int getBitrate() {
		int rawBitrate = Math.round(getSize() * 8 / getDuration() / 1000);
		return MapBitrate(rawBitrate);
	}
	
	////////////// Static functions 
	public static int MapBitrate(int rawBitrate) {
		int[] mappings = new int[] {8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 192, 224, 256, 320};
		for(int map : mappings) {
			if((rawBitrate * 0.9) < map && (rawBitrate * 1.1) > map) {
				return map;
			}
		}
		return rawBitrate;
	}
	
	public static int bytesToMB(int bytes) {
		return Math.round(bytes / 1024 / 1024 * 100) / 100;
	}
	
	public static String secondsToMMSS(int sec) {
		int minutes = sec / 60;
		int seconds = sec % 60;
		return ((minutes < 10 ? "0" : "") + minutes	+ ":" + (seconds < 10 ? "0" : "") + seconds);
	}
	
}
